<%-- 
    Document   : newcustomer
    Created on : Nov 24, 2011, 2:14:46 AM
    Author     : Venus
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*, Beans.LoaiKH,Beans.ThamSoHT, Models.ThamSoHT_Model, Models.LoaiKH_Model, Models.KhachHang_Model"%>
<script type="text/javascript">
    function keypress(e){
        //Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
        var keypressed = null;
        if (window.event)
        {
            keypressed = window.event.keyCode; //IE
        }
        else
        {
            keypressed = e.which; //NON-IE, Standard
        }
        if (keypressed < 48 || keypressed > 57 )
        { //CharCode của 0 là 48 (Theo bảng mã ASCII)
            //CharCode của 9 là 57 (Theo bảng mã ASCII)
            if (keypressed == 8 || keypressed == 127  )
            {//Phím Delete và Phím Back
                return;
            }
            return false;
        }
    }
</script>
<%
            int langid = (Integer) session.getAttribute("langid"); // ngôn ngữ hiện tại
            String dsts = " 'changemark', 'notice', 'order', 'enable', 'disable', 'all', 'status', 'rightmsg', 'checksubmitmsg', 'customer', 'createcustomer', 'nameofcustomer', 'customertype', 'mark', 'address', 'phonenumber', 'birthday', 'save', 'customerlist' ";
            ThamSoHT[] mdsts = ThamSoHT_Model.DSThamSo(dsts, langid); // mảng chứa các tham số của trang này.

            String address = mdsts[0].getTenTS();
            String all = mdsts[1].getTenTS();
            String birthday = mdsts[2].getTenTS();
            String changemark = mdsts[3].getTenTS();
            String checksubmitmsg = mdsts[4].getTenTS();
            String createcustomer = mdsts[5].getTenTS();
            String customer = mdsts[6].getTenTS();
            String customerlist = mdsts[7].getTenTS();
            String customertype = mdsts[8].getTenTS();
            String disable = mdsts[9].getTenTS();
            String enable = mdsts[10].getTenTS();
            String mark = mdsts[11].getTenTS();
            String nameofcustomer = mdsts[12].getTenTS();
            String notice = mdsts[13].getTenTS();
            String order = mdsts[14].getTenTS();
            String phonenumber = mdsts[15].getTenTS();
            String rightmsg = mdsts[16].getTenTS();
            String save = mdsts[17].getTenTS();
            String status = mdsts[18].getTenTS();

            String msgright = notice + "/" + rightmsg;
            String msgchecksubmit = notice + "/" + checksubmitmsg;

            Vector vDSKH = (Vector) request.getAttribute("DSKH");
            Vector vDSLKH = (Vector) request.getAttribute("DSLKH");
            int numpage = 0;// khởi tạo số trang = 0
            int vsize = vDSKH.size();
            if (vsize % 6 == 0) // mỗi trang có 6 dòng
            {
                numpage = vsize / 6;
            } else {
                numpage = vsize / 6 + 1;
            }
            String xx = (String) request.getAttribute("item"); // trang hiện tại đang xem
            int item = Integer.parseInt(xx);

%>
<script type="text/javascript">
    $(function(){
        $('#datepicker1').datepicker($.datepicker.regional['vi']);
        $( "#datepicker1" ).datepicker( "option", "dateFormat","dd/mm/yy");
    });
</script>
<h1><img style="margin-right: 13px; opacity: 0.8; margin-top: 4px;" alt="" src="../images/customer1.png"><%=customer%></h1>
<div class="cb"></div>
<div id="phanquyen">
    <div id="ShowTaoKH" class="bloc" style="width: 87%; margin-top: 8px; " >
        <div class="title">
            <%=createcustomer%>            
        </div>
        <div class="content">
            <form name="createcustomer" class="customerinfo" action="">
                <div style=" float: left; margin-right: 50px; margin-left: 35px;">
                    <div style=" margin: 0 10px 8px;">
                        <div style=" width: 120px; float: left; "><%=customertype%></div>
                        <select style=" width: 200px; padding-bottom: 4px; padding-top: 4px; height: 27px;" class="text" id="select" name="lkh" >
                            <%
                                        for (int i = 0; i < vDSLKH.size(); i++) {
                                            Beans.LoaiKH lkh = (Beans.LoaiKH) vDSLKH.elementAt(i);
                            %>
                            <option value="<%=lkh.getMaLKH()%>" ><%= lkh.getTenLKH()%></option>
                            <%  }
                            %>
                        </select>
                    </div>
                    <div style=" margin: 0 10px 8px;">
                        <div style=" width: 120px; float: left; "><%=nameofcustomer%></div>
                        <input style=" width: 200px;" type="text" class="text" name="tenkh" >
                    </div>
                    <div style=" margin: 0 10px 8px;">
                        <div style=" width: 120px; float: left; "><%=mark%></div>
                        <input style=" width: 200px;" type="text" class="text" name="mark" value="0" disabled >
                    </div>
                </div>
                <div>
                    <div style=" margin: 0 10px 8px;">
                        <div style=" width: 120px; float: left;"><%=address%></div>
                        <input style=" width: 200px;" type="text" class="text" name="diachi">
                    </div>
                    <div style=" margin: 0 10px 8px;">
                        <div style=" width: 120px; float: left;"><%=phonenumber%></div>
                        <input style=" width: 200px;" type="text" class="text" name="sodt" onkeypress="return keypress(event)" >
                    </div>
                    <div style=" margin: 0 10px 8px;">
                        <div style=" width: 120px; float: left;"><%=birthday%></div>
                        <input style=" width: 200px;" type="text" id="datepicker1" class="text" name="birthday" >
                    </div>
                </div>
                <div class="cb"></div>
                <input style=" margin-left: 370px; " class="button" type="button"  value="<%=save%>" lang="<%=msgright%>" alt="<%=msgchecksubmit%>" onclick="CreateCustomer(this.lang, this.alt)">
            </form>
        </div>
    </div>
    <div id="DSKH" class="bloc" style=" margin-top: 15px; width: 87%;">
        <div class="title">
            <%=customerlist%><a href="#" lang="<%=msgright%>" title="<%=changemark%>" onclick="DoiDiem(this.lang)" style=" float: right; " ><img style="height: 35px; width: 35px; margin-top: 3px; opacity: 0.8;" alt="" src="../images/doidiem1.png"></a>
        </div>
        <div class="content">
            <form name="dskh" action="">
                <table class="mytable" border="0" cellpadding="0" cellspacing="0">
                    <thead>
                        <tr>
                            <th style="width: 9%;"><%=order%></th>
                            <th style=" width: 20%;">
                                <a href="#" id="titledskv1" style="margin-top: 5px;" class="down" lang="<%=msgright%>" name="1" onclick="SortHoTenKH(this.name , this.className, this.lang)">
                                    <div style="float:left"><%=nameofcustomer%></div>
                                    <div style=" margin-right: 45px;" id="sortkv1" class="down1"></div>
                                </a>
                            </th>
                            <th style=" width: 22%;">
                                <a href="#" id="titledskv2" style="margin-top: 5px;" class="down" lang="<%=msgright%>" name="1" onclick="SortDiemKH(this.name , this.className, this.lang)">
                                    <div style="float:left"><%=mark%></div>
                                    <div style=" margin-right: 45px;" id="sortkv2" class="down1"></div>
                                </a>
                            </th>
                            <th style=" width: 24%;">
                                <a href="#" id="titledskv3" style="margin-top: 5px;" class="down" lang="<%=msgright%>" name="1" onclick="SortLoaiKH(this.name , this.className, this.lang)">
                                    <div style="float:left"><%=customertype%></div>
                                    <div style=" margin-right: 60px;" id="sortkv3" class="down1"></div>
                                </a>
                            </th>
                            <th style="margin-top: 2px; width: 20%;">
                                <a href="#" id="titledskv4" class="down" lang="<%=msgright%>" name="1" onclick="SortTTKH(this.name , this.className, this.lang)">
                                    <div><%=status%></div>
                                    <div >
                                        <div id="sortkv4" class="down2"></div>
                                        <div id="sortkv4" class="up2" style="display:none;"></div>
                                    </div>
                                </a>
                            </th>
                        </tr>
                        <tr id="searchKH" >
                            <th><img onclick="SearchCustomer( this.alt, this.lang)" lang="<%=msgright%>" style=" margin-top: 2px; margin-left: 3px; margin-bottom: -7px; cursor: pointer;"  alt="1" src="../images/search1.png"></th>
                            <th >
                                <input type="textbox" style=" width: 120px;"   class="hoten text" >
                            </th>
                            <th >
                                <input type="textbox" style=" width: 125px;"  class="sodiem text"  onkeypress="return keypress(event)">
                            </th>
                            <th>
                                <select  lang="<%=msgright%>" id="1"  class="loaikh" onchange="SearchCustomer( this.id, this.lang)">
                                    <option value="all"><%=all%></option>
                                    <%
                                                for (int i = 0; i < vDSLKH.size(); i++) {
                                                    Beans.LoaiKH lkh = (Beans.LoaiKH) vDSLKH.elementAt(i);
                                    %>
                                    <option value="<%=lkh.getMaLKH()%>" ><%= lkh.getTenLKH()%></option>
                                    <%  }
                                    %>
                                </select>
                            </th>
                            <th>
                                <select class="tinhtrang" id="1"  lang="<%=msgright%>" onchange="SearchCustomer( this.id, this.lang)">
                                    <option value="all"><%= all%></option>
                                    <option value="1"><%=enable%></option>
                                    <option value="0"><%=disable%></option>
                                </select>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <%
                                    for (int i = (item - 1) * 6; i < (item - 1) * 6 + 6 && i < vsize; i++) {
                                        Beans.KhachHang kh = (Beans.KhachHang) vDSKH.elementAt(i);
                        %>
                        <tr>
                            <td class="STT"><%= i + 1%></td>
                            <td><a href="#" name="<%=kh.getMaKH()%>" lang="<%=msgright%>" onclick="UpdateDetailKH( this.name, this.lang)"><%=kh.getHoTen()%></a></td>
                            <td ><%=kh.getDiemTL()%></td>
                            <td>
                                <select  class="<%= kh.getMaKH()%>" lang="<%=msgright%>" onchange="UpdateLKH(this.value,  this.className, this.lang)">
                                    <option value="<%=kh.getMaLKH()%>"><%=KhachHang_Model.LayTenLoaiKH(kh.getMaLKH(), langid)%></option>
                                    <%
                                                            LoaiKH[] dslkh = LoaiKH_Model.DSLoaiKH(kh.getMaLKH(), langid);
                                                            for (int k = 0; k < dslkh.length; k++) {%>
                                    <option value="<%=dslkh[k].getMaLKH()%>"><%=dslkh[k].getTenLKH()%></option>
                                    <%  }
                                    %>
                                </select>
                            </td>
                            <td>
                                <select  class="<%= kh.getMaKH()%>" lang="<%=msgright%>" onchange="UpdateStatusKH(this.value,  this.className, this.lang)">
                                    <%
                                                            if (kh.getTinhTrang() == 1) {%>
                                    <option value="1"><%= enable%></option>
                                    <option value="0"><%= disable%></option>
                                    <%  } else {%>
                                    <option value="0"><%= disable%></option>
                                    <option value="1"><%= enable%></option>
                                    <%  }
                                    %>
                                </select>
                            </td>
                        </tr>
                        <%  }
                        %>
                    </tbody>
                </table>
                <div class="pagination">
                    <%
                                int trang = 1;
                                if (item > 1) {
                                    trang = item - 1;
                                }
                    %>
                    <%
                            if (vsize > 6) {%>
                    <a href="#" class="prev" lang="<%=msgright%>"  name="<%= trang%>" onclick="Customer(this.name, this.lang)">«</a>
                    <%  for (int c = 1; c <= numpage; c++) {
                                                if (c != item) {
                    %>          <a href="#" lang="<%=msgright%>" name="<%= c%>" onclick="Customer(this.name, this.lang)" ><%= c%></a>
                    <%      } else {%><a class="current"> <%= c%></a> <% }
                                            }
                    %>
                    <%
                                            if (item + 1 <= numpage) {
                                                trang = item + 1;
                                            } else {
                                                trang = item;
                                            }
                    %>  <a href="#" class="next" lang="<%=msgright%>" name="<%= trang%>" onclick="Customer(this.name, this.lang)">»</a>
                    <%  }
                    %>
                </div>
            </form>
        </div>
    </div>
</div>